import { ApiResponse } from '@monorepo/shared-types';

export function createApiResponse<T>(data: T, success = true, message?: string): ApiResponse<T> {
  return {
    data,
    success,
    message
  };
}

export function formatDate(date: Date): string {
  return date.toISOString().split('T')[0];
}

export function debounce<F extends (...args: any[]) => any>(
  func: F,
  waitFor: number
): (...args: Parameters<F>) => void {
  let timeout: ReturnType<typeof setTimeout> | null = null;

  return function(...args: Parameters<F>): void {
    if (timeout !== null) {
      clearTimeout(timeout);
    }
    timeout = setTimeout(() => func(...args), waitFor);
  };
} 